import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Executor;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class Demo5 {
    public static void main(String[] args) throws InterruptedException {
        ExecutorService service= Executors.newFixedThreadPool(5);
        CountDownLatch countDownLatch=new CountDownLatch(20);
        for (int i = 0; i < 20; i++) {
            int id=i;
            service.submit(()->{
                System.out.println("下载任务"+id+"开始下载");
                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("下载任务"+id+"下载完成");
                countDownLatch.countDown();
            });
        }
        countDownLatch.await();
        System.out.println("任务全部完成");
    }
}
